package com.ruoyi.erp.controller;

import java.util.List;

import com.ruoyi.erp.domain.DictProjectHourModule;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.ProjectHourModule;
import com.ruoyi.erp.service.IProjectHourModuleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工时模块Controller
 * 
 * @author sauger
 * @date 2022-04-06
 */
@Controller
@RequestMapping("/erp/projectHour/module")
public class ProjectHourModuleController extends BaseController
{
    private String prefix = "erp/projectHour/module";

    @Autowired
    private IProjectHourModuleService projectHourModuleService;

    @RequiresPermissions("erp:module:view")
    @GetMapping()
    public String module()
    {
        return prefix + "/module";
    }

    /**
     * 查询工时模块列表
     */
    @RequiresPermissions("erp:module:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProjectHourModule projectHourModule)
    {
        startPage();
        List<ProjectHourModule> list = projectHourModuleService.selectProjectHourModuleList(projectHourModule);
        return getDataTable(list);
    }

    /**
     * 导出工时模块列表
     */
    @RequiresPermissions("erp:module:export")
    @Log(title = "工时模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProjectHourModule projectHourModule)
    {
        List<ProjectHourModule> list = projectHourModuleService.selectProjectHourModuleList(projectHourModule);
        ExcelUtil<ProjectHourModule> util = new ExcelUtil<ProjectHourModule>(ProjectHourModule.class);
        return util.exportExcel(list, "工时模块数据");
    }

    /**
     * 新增工时模块
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工时模块
     */
    @RequiresPermissions("erp:module:add")
    @Log(title = "工时模块", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProjectHourModule projectHourModule)
    {
        projectHourModuleService.insertProjectHourModule(projectHourModule);
        return success(projectHourModule);
    }

    /**
     * 修改工时模块
     */
    @RequiresPermissions("erp:module:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        ProjectHourModule projectHourModule = projectHourModuleService.selectProjectHourModuleById(id);
        mmap.put("projectHourModule", projectHourModule);
        return prefix + "/edit";
    }

    /**
     * 修改保存工时模块
     */
    @RequiresPermissions("erp:module:edit")
    @Log(title = "工时模块", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProjectHourModule projectHourModule)
    {
        projectHourModule.setCreateUserId(getUserId().intValue());
        return toAjax(projectHourModuleService.updateProjectHourModule(projectHourModule));
    }

    /**
     * 删除工时模块
     */
    @RequiresPermissions("erp:module:remove")
    @Log(title = "工时模块", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(projectHourModuleService.deleteProjectHourModuleByIds(ids));
    }

    @GetMapping("/myProjectModules/{flag}")
    @ResponseBody
    public List<DictProjectHourModule> getMyProjectModules(@PathVariable("flag") String flag)
    {
        return projectHourModuleService.selectDictProjectHourModule(getUserId().intValue(),flag);
    }
}
